import { defHttp } from '/@/utils/http/axios';
import { PageResult } from '@/api/model/pageResult';
import { ContentTypeEnum } from '@/enums/httpEnum';
import { QueryMemberCouponBo } from '@/api/base-data/member-coupon/model/queryMemberCouponBo';
import { QueryMemberCouponVo } from '@/api/base-data/member-coupon/model/queryMemberCouponVo';
import { GetMemberCouponBo } from '@/api/base-data/member-coupon/model/getMemberCouponBo';
import { CreateMemberCouponVo } from '@/api/base-data/member-coupon/model/createMemberCouponVo';
import { UpdateMemberCouponVo } from '@/api/base-data/member-coupon/model/updateMemberCouponVo';
import { CouponGrantVo } from '@/api/base-data/member-coupon/model/couponGrantVo';

const baseUrl = '/basedata/member/coupon';
const region = 'cloud-api';

/**
 * 查询列表
 * @param params
 * @returns {Promise}
 */
export function query(params: QueryMemberCouponVo): Promise<PageResult<QueryMemberCouponBo>> {
  return defHttp.get<PageResult<QueryMemberCouponBo>>(
    {
      url: baseUrl + '/query',
      params: params,
    },
    {
      region,
    },
  );
}

/**
 * 根据ID查询
 * @param id
 * @returns {Promise}
 */
export function get(id: String): Promise<GetMemberCouponBo> {
  return defHttp.get<GetMemberCouponBo>(
    {
      url: baseUrl,
      params: {
        id,
      },
    },
    {
      region,
    },
  );
}

/**
 * 新增
 * @param params
 * @returns {Promise}
 */
export function create(params: CreateMemberCouponVo): Promise<void> {
  return defHttp.post<void>(
    {
      url: baseUrl,
      data: params,
    },
    {
      contentType: ContentTypeEnum.JSON,
      region,
    },
  );
}

/**
 * 修改
 * @param params
 * @returns {Promise}
 */
export function update(params: UpdateMemberCouponVo): Promise<void> {
  return defHttp.put<void>(
    {
      url: baseUrl,
      data: params,
    },
    {
      contentType: ContentTypeEnum.JSON,
      region,
    },
  );
}

/**
 * 发放卡券
 * @param params
 */
export function couponGrant(params: CouponGrantVo): Promise<void> {
  return defHttp.post<void>(
    {
      url: baseUrl + '/grant',
      data: params,
    },
    {
      contentType: ContentTypeEnum.JSON,
      region,
    },
  );
}
